package lancooPaperAnswer;

import android.content.Context;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.lancooznbk.R;
import com.example.lancooznbk.presenter.PaperDef;

import lancooControl.Control;
import lancooControl.CustomAnswerFillView;

import static android.view.View.GONE;
import static testPaperCTCS.GuessTestingPaperActivity.InforGuessTesting;
import static testPaperFavoritesPage.FavoritesPagePaperActivity.InforFavoritesPage;
import static testPaperJBFX.BasicReviewPaperActivity.InforBasicReview;
import static testPaperNDFX.DifficultReviewPaperActivity.InforDifficultReview;
import static testPaperWrong.WrongQuesPaperActivity.InforWrongQues;
import static testPaperWrongHistory.HistoryWrongQuesPaperActivity.InforHistoryWrongQues;

/**
 * Created by Administrator on 2017/9/25/025.
 */

public class AnswerDwtkAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private Context mContext;
    //当前试题数量
    private int SumItem;
    //当前试题在当前试卷的ID
    private int PaperID;
    private int ModelFrom;//试卷来源

    private int tvBlack;
    private int tvBlue;
    private int tvWhite;
    private int tvGreen;
    private int tvRed;
    private int tvGray;

    /*
    * 试题相关信息
    * */
    private int totalItemCount;//小题数量
    private int state;//试卷的作答状态
    private double score;//试题总分值
    private String[] answer;//正确答案
    private String[] stuAnswer;//用户答案
    private String[] analysis;//答案解析
    private String[] stuAssess;//自评/机评结果

    private ViewHolder holder = null;

    public class ViewHolder {
        LinearLayout LayoutAnswerArea;//作答区
        LinearLayout LayoutAnalysis;//回看解析区
        TextView TvAnswer;//正确答案
        //        TextView TvStuAnswer;//学生答案
        TextView TvScore;//得分
        TextView TvAnalysis;//解析
        LinearLayout LayoutStuAssess;//自评显示区
        TextView TvStuAssess;//自评内容

        LinearLayout LayoutClassicExample;//经典案例显示区
        LinearLayout LayoutClassicMenu;//参考答案及解析按钮
        ImageView IvClassic;//参考答案及解析箭头
        LinearLayout LayoutClassic;//参考答案及解析显示区
        TextView TvClassicAnswer;//参考答案
        TextView TvClassicAnalysis;//解析

        public ViewHolder(View convertView) {
            LayoutAnswerArea = (LinearLayout) convertView.findViewById(R.id.layout_answer_area);
            LayoutAnalysis = (LinearLayout) convertView.findViewById(R.id.layout_analysis);
            TvAnswer = (TextView) convertView.findViewById(R.id.tv_answer);
//            TvStuAnswer = (TextView) convertView.findViewById(R.id.tv_stuanswer);
            TvScore = (TextView) convertView.findViewById(R.id.tv_score);
            TvAnalysis = (TextView) convertView.findViewById(R.id.tv_analysis);
            LayoutStuAssess = (LinearLayout) convertView.findViewById(R.id.layout_stu_assess);
            TvStuAssess = (TextView) convertView.findViewById(R.id.tv_stu_assess);

            LayoutClassicExample = (LinearLayout) convertView.findViewById(R.id.layout_classic_example);
            LayoutClassicMenu = (LinearLayout) convertView.findViewById(R.id.layout_classic_menu);
            LayoutClassicMenu.setOnClickListener(new clickListener());
            IvClassic = (ImageView) convertView.findViewById(R.id.iv_classic);
            LayoutClassic = (LinearLayout) convertView.findViewById(R.id.layout_classic);
            TvClassicAnswer = (TextView) convertView.findViewById(R.id.tv_classic_answer);
            TvClassicAnalysis = (TextView) convertView.findViewById(R.id.tv_classic_analysis);
        }
    }


    public AnswerDwtkAdapter(Context context, int sumItem, int paperID, int modelFrom) {
        mInflater = LayoutInflater.from(context);
        this.mContext = context;
        this.SumItem = sumItem;
        this.PaperID = paperID;
        this.ModelFrom = modelFrom;

    }

    @Override
    public int getCount() {
        return SumItem;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.adapter_answer_dwtk_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        /*
        * 获取试题相关信息
        * */
        getQuesInfor();

        /*
        * 显示相关作答信息
        * */
        showQuesInfor();

        /*
       * 已提交状态试题分析部分内容展示
       * */
        showAnalysis();


        return convertView;
    }

    /*
    * 获取试题相关信息
    * */
    private void getQuesInfor() {

        tvBlack = mContext.getResources().getColor(R.color.black);
        tvBlue = mContext.getResources().getColor(R.color.blue);
        tvWhite = mContext.getResources().getColor(R.color.white);
        tvGreen = mContext.getResources().getColor(R.color.green);
        tvRed = mContext.getResources().getColor(R.color.red);
        tvGray = mContext.getResources().getColor(R.color.gray);

        if (ModelFrom == PaperDef.FROM_BASE_REVIEW) {

            //试题小题数量
            totalItemCount = InforBasicReview.getPaperContent().get(PaperID).getTotalItemCount();
            //试题的作答状态
            state = InforBasicReview.getState();
            //试题总分值
            score = InforBasicReview.getPaperContent().get(PaperID).getScore();

            //正确答案
            answer = new String[totalItemCount];
            //学生答案
            stuAnswer = new String[totalItemCount];
            //答案解析
            analysis = new String[totalItemCount];
            //自评/机评结果
            stuAssess = new String[totalItemCount];
            //本题是否可自评
//            isAssess[i] = TestPaperBasicReviewActivity.InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getIsAssess();

            for (int i = 0; i < totalItemCount; i++) {
                answer[i] = new String();
                answer[i] = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getAnswer();
                stuAnswer[i] = new String();
                stuAnswer[i] = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                analysis[i] = new String();
                analysis[i] = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getAnalysis();
                stuAssess[i] = new String();
                stuAssess[i] = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
//                isAssess[i] = TestPaperBasicReviewActivity.InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getIsAssess();
            }

            String stuAnswerAll = "";
            String stuAssessAll = "";
            for (int i = 0; i < totalItemCount; i++) {
                if (i == 0) {
                    stuAnswerAll = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                } else {
                    stuAnswerAll = stuAnswerAll + "#$*#" + InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = stuAssessAll + "#$*#" + InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                }
            }
            InforBasicReview.getPaperContent().get(PaperID).setStuAnswerOldAll(stuAnswerAll);
            InforBasicReview.getPaperContent().get(PaperID).setStuAssessOldAll(stuAssessAll);
            InforBasicReview.getPaperContent().get(PaperID).setStuAnswerNewAll(stuAnswerAll);
            InforBasicReview.getPaperContent().get(PaperID).setStuAssessNewAll(stuAssessAll);

        }  else if(ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW){

            //试题小题数量
            totalItemCount = InforDifficultReview.getTotalItemCount();
            //试题的作答状态
            state = InforDifficultReview.getState();
            //试题总分值
            score = InforDifficultReview.getScore();

            //正确答案
            answer = new String[totalItemCount];
            //学生答案
            stuAnswer = new String[totalItemCount];
            //答案解析
            analysis = new String[totalItemCount];
            //自评/机评结果
            stuAssess = new String[totalItemCount];

            for(int i =0;i<totalItemCount;i++){
                answer[i] = new String();
                answer[i] = InforDifficultReview.getQueList().get(i).getAnswer();
                stuAnswer[i] = new String();
                stuAnswer[i] = InforDifficultReview.getQueList().get(i).getStuAnswer();
                analysis[i] = new String();
                analysis[i] = InforDifficultReview.getQueList().get(i).getAnalysis();
                stuAssess[i] = new String();
                stuAssess[i] = InforDifficultReview.getQueList().get(i).getStuAssess();
//                isAssess[i] = TestPaperBasicReviewActivity.InforBasicReview.getQueList().get(i).getIsAssess();
            }

            String stuAnswerAll = "";
            String stuAssessAll = "";
            for (int i = 0; i < totalItemCount; i++) {
                if(i==0){
                    stuAnswerAll = InforDifficultReview.getQueList().get(i).getStuAnswer();
                    stuAssessAll = InforDifficultReview.getQueList().get(i).getStuAssess();
                }else{
                    stuAnswerAll = stuAnswerAll+"#$*#"+InforDifficultReview.getQueList().get(i).getStuAnswer();
                    stuAssessAll = stuAssessAll+"#$*#"+InforDifficultReview.getQueList().get(i).getStuAssess();
                }
            }
            InforDifficultReview.setStuAnswerOldAll(stuAnswerAll);
            InforDifficultReview.setStuAssessOldAll(stuAssessAll);
            InforDifficultReview.setStuAnswerNewAll(stuAnswerAll);
            InforDifficultReview.setStuAssessNewAll(stuAssessAll);

        } else if (ModelFrom == PaperDef.FROM_GUESS_REVIEW) {
            //试题小题数量
            totalItemCount = InforGuessTesting.getPaperContent().get(PaperID).getTotalItemCount();
            //试题的作答状态
            state = InforGuessTesting.getState();
            //试题总分值
            score = InforGuessTesting.getPaperContent().get(PaperID).getScore();

            //正确答案
            answer = new String[totalItemCount];
            //学生答案
            stuAnswer = new String[totalItemCount];
            //答案解析
            analysis = new String[totalItemCount];
            //自评/机评结果
            stuAssess = new String[totalItemCount];
            //本题是否可自评
//            isAssess[i] = TestPaperBasicReviewActivity.InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getIsAssess();

            for (int i = 0; i < totalItemCount; i++) {
                answer[i] = new String();
                answer[i] = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getAnswer();
                stuAnswer[i] = new String();
                stuAnswer[i] = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                analysis[i] = new String();
                analysis[i] = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getAnalysis();
                stuAssess[i] = new String();
                stuAssess[i] = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
//                isAssess[i] = TestPaperBasicReviewActivity.InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getIsAssess();
            }

            String stuAnswerAll = "";
            String stuAssessAll = "";
            for (int i = 0; i < totalItemCount; i++) {
                if (i == 0) {
                    stuAnswerAll = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                } else {
                    stuAnswerAll = stuAnswerAll + "#$*#" + InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = stuAssessAll + "#$*#" + InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                }
            }
            InforGuessTesting.getPaperContent().get(PaperID).setStuAnswerOldAll(stuAnswerAll);
            InforGuessTesting.getPaperContent().get(PaperID).setStuAssessOldAll(stuAssessAll);
            InforGuessTesting.getPaperContent().get(PaperID).setStuAnswerNewAll(stuAnswerAll);
            InforGuessTesting.getPaperContent().get(PaperID).setStuAssessNewAll(stuAssessAll);
        }else if (ModelFrom == PaperDef.FROM_BASE_REVIEW_WRONG||ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG) {
            //试题小题数量
            totalItemCount = InforWrongQues.get(PaperID).getTotalItemCount();
            //试题的作答状态
            state = InforWrongQues.get(PaperID).getState();
            //试题总分值
            score = InforWrongQues.get(PaperID).getScore();

            //正确答案
            answer = new String[totalItemCount];
            //学生答案
            stuAnswer = new String[totalItemCount];
            //答案解析
            analysis = new String[totalItemCount];
            //自评/机评结果
            stuAssess = new String[totalItemCount];

            for (int i = 0; i < totalItemCount; i++) {
                answer[i] = new String();
                answer[i] = InforWrongQues.get(PaperID).getQueList().get(i).getAnswer();
                stuAnswer[i] = new String();
                stuAnswer[i] = InforWrongQues.get(PaperID).getQueList().get(i).getStuAnswer();
                analysis[i] = new String();
                analysis[i] = InforWrongQues.get(PaperID).getQueList().get(i).getAnalysis();
                stuAssess[i] = new String();
                stuAssess[i] = InforWrongQues.get(PaperID).getQueList().get(i).getStuAssess();
            }

            String stuAnswerAll = "";
            String stuAssessAll = "";
            for (int i = 0; i < totalItemCount; i++) {
                if (i == 0) {
                    stuAnswerAll = InforWrongQues.get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = InforWrongQues.get(PaperID).getQueList().get(i).getStuAssess();
                } else {
                    stuAnswerAll = stuAnswerAll + "#$*#" + InforWrongQues.get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = stuAssessAll + "#$*#" + InforWrongQues.get(PaperID).getQueList().get(i).getStuAssess();
                }
            }
            InforWrongQues.get(PaperID).setStuAnswerOldAll(stuAnswerAll);
            InforWrongQues.get(PaperID).setStuAssessOldAll(stuAssessAll);
            InforWrongQues.get(PaperID).setStuAnswerNewAll(stuAnswerAll);
            InforWrongQues.get(PaperID).setStuAssessNewAll(stuAssessAll);
        }else if(ModelFrom==PaperDef.FROM_BASE_REVIEW_WRONG_History||ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG_History){
            //试题小题数量
            totalItemCount = InforHistoryWrongQues.get(PaperID).getTotalItemCount();
            //试题的作答状态
            state = InforHistoryWrongQues.get(PaperID).getState();
            //试题总分值
            score = InforHistoryWrongQues.get(PaperID).getScore();

            //正确答案
            answer = new String[totalItemCount];
            //学生答案
            stuAnswer = new String[totalItemCount];
            //答案解析
            analysis = new String[totalItemCount];
            //自评/机评结果
            stuAssess = new String[totalItemCount];

            for (int i = 0; i < totalItemCount; i++) {
                answer[i] = new String();
                answer[i] = InforHistoryWrongQues.get(PaperID).getQueList().get(i).getAnswer();
                stuAnswer[i] = new String();
                stuAnswer[i] = InforHistoryWrongQues.get(PaperID).getQueList().get(i).getStuAnswer();
                analysis[i] = new String();
                analysis[i] = InforHistoryWrongQues.get(PaperID).getQueList().get(i).getAnalysis();
                stuAssess[i] = new String();
                stuAssess[i] = InforHistoryWrongQues.get(PaperID).getQueList().get(i).getStuAssess();
            }

            String stuAnswerAll = "";
            String stuAssessAll = "";
            for (int i = 0; i < totalItemCount; i++) {
                if (i == 0) {
                    stuAnswerAll = InforHistoryWrongQues.get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = InforHistoryWrongQues.get(PaperID).getQueList().get(i).getStuAssess();
                } else {
                    stuAnswerAll = stuAnswerAll + "#$*#" + InforHistoryWrongQues.get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = stuAssessAll + "#$*#" + InforHistoryWrongQues.get(PaperID).getQueList().get(i).getStuAssess();
                }
            }
            InforHistoryWrongQues.get(PaperID).setStuAnswerOldAll(stuAnswerAll);
            InforHistoryWrongQues.get(PaperID).setStuAssessOldAll(stuAssessAll);
            InforHistoryWrongQues.get(PaperID).setStuAnswerNewAll(stuAnswerAll);
            InforHistoryWrongQues.get(PaperID).setStuAssessNewAll(stuAssessAll);
        }else if(ModelFrom==PaperDef.FROM_FAVOURITE_REVIEW){
            //试题小题数量
            totalItemCount = InforFavoritesPage.getTotalItemCount();
            //试题的作答状态
            state = InforFavoritesPage.getState();
            //试题总分值
            score = InforFavoritesPage.getScore();

            //正确答案
            answer = new String[totalItemCount];
            //学生答案
            stuAnswer = new String[totalItemCount];
            //答案解析
            analysis = new String[totalItemCount];
            //自评/机评结果
            stuAssess = new String[totalItemCount];

            for(int i =0;i<totalItemCount;i++){
                answer[i] = new String();
                answer[i] = InforFavoritesPage.getQueList().get(i).getAnswer();
                stuAnswer[i] = new String();
                stuAnswer[i] = InforFavoritesPage.getQueList().get(i).getStuAnswer();
                analysis[i] = new String();
                analysis[i] = InforFavoritesPage.getQueList().get(i).getAnalysis();
                stuAssess[i] = new String();
                stuAssess[i] = InforFavoritesPage.getQueList().get(i).getStuAssess();
            }
        }
    }

    /*
    * 显示相关作答信息
    * */
    private void showQuesInfor() {

        CustomAnswerFillView AnswerEdt[] = new CustomAnswerFillView[totalItemCount];
        for (int i = 0; i < totalItemCount; i++) {
            AnswerEdt[i] = new CustomAnswerFillView(mContext);
            if (state == 2 || (PaperID == 0 && ModelFrom == PaperDef.FROM_BASE_REVIEW_WRONG) || (PaperID == 0 && ModelFrom == PaperDef.FROM_DIFFERENT_REVIEW_WRONG)) {
                if (!stuAssess[i].equals("")) {//已自评
                    if (stuAnswer[i].equals("")) {
                        if (!stuAnswer[i].equals("")) {
                            if (stuAnswer[i].equals(answer[i])) {
                                AnswerEdt[i].setAnswerFill(i + 1, stuAnswer[i], "", tvGreen);
                            } else if (!stuAnswer[i].equals(answer[i])) {
                                AnswerEdt[i].setAnswerFill(i + 1, stuAnswer[i], "", tvRed);
                            }
                        } else {
                            AnswerEdt[i].setAnswerFill(i + 1, "", "已在纸面完成作答", tvGray);
                        }
                    } else {
                        if (!stuAnswer[i].equals("")) {
                            if (stuAnswer[i].equals(answer[i])) {
                                AnswerEdt[i].setAnswerFill(i + 1, stuAnswer[i], "", tvGreen);
                            } else if (!stuAnswer[i].equals(answer[i])) {
                                AnswerEdt[i].setAnswerFill(i + 1, stuAnswer[i], "", tvRed);
                            }
                        } else {
                            AnswerEdt[i].setAnswerFill(i + 1, "", "未作答", tvGray);
                        }
                    }
                } else {//未自评
                    if (stuAnswer[i].equals("")) {
                        Log.e("=====000=====", "=====000====");
                        AnswerEdt[i].setAnswerFill(i + 1, "", "未作答", tvGray);
                    } else {
                        if (stuAnswer[i].equals(answer[i])) {
                            Log.e("=====000=====", "=====111====");
                            AnswerEdt[i].setAnswerFill(i + 1, stuAnswer[i], "", tvGreen);
                        } else {
                            Log.e("=====000=====", "=====222====");
                            AnswerEdt[i].setAnswerFill(i + 1, stuAnswer[i], "", tvRed);
                        }
                    }
                }

            } else {
                AnswerEdt[i].setAnswerFill(i + 1, stuAnswer[i], "请在这里输入答案...", tvBlack);
            }

            if (state == 2 || (PaperID == 0 && ModelFrom == PaperDef.FROM_BASE_REVIEW_WRONG) ||
                    (PaperID == 0 && ModelFrom == PaperDef.FROM_DIFFERENT_REVIEW_WRONG)) {
                AnswerEdt[i].EdtFill.setFocusable(false);
            }

            final int finalI = i;
            AnswerEdt[i].EdtFill.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable s) {
                    Log.e("======after====", finalI + "====ssss===" + s.toString());
                    setStuAnswer(s.toString(), finalI);
                }
            });

            if (state == 2 || (PaperID == 0 && ModelFrom == PaperDef.FROM_BASE_REVIEW_WRONG) ||
                    (PaperID == 0 && ModelFrom == PaperDef.FROM_DIFFERENT_REVIEW_WRONG)) {
                AnswerEdt[i].EdtFill.setClickable(false);
                AnswerEdt[i].EdtFill.setFocusable(false);
            }

            holder.LayoutAnswerArea.addView(AnswerEdt[i]);
        }
    }


    /*
   * 已提交状态试题分析部分内容展示
   * */
    private void showAnalysis() {

        if((PaperID==1&&(ModelFrom==PaperDef.FROM_BASE_REVIEW_WRONG||ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG))||
                ModelFrom==PaperDef.FROM_FAVOURITE_REVIEW){
            holder.LayoutAnalysis.setVisibility(View.GONE);
            holder.LayoutClassicExample.setVisibility(View.VISIBLE);
            holder.LayoutAnswerArea.setVisibility(View.GONE);
            holder.LayoutClassic.setVisibility(View.GONE);

            String answerAll = "";
            String analysisAll = "";
            for(int i =0;i<totalItemCount;i++){
                answerAll = answerAll+"<br>"+(i+1)+"、"+answer[i]+"<br>";
                if(analysis[i].equals("")){
                    analysis[i]="暂无解析";
                }
                analysisAll =analysisAll+"<br>"+(i+1)+"、"+analysis[i]+"<br>";

            }
            holder.TvClassicAnswer.setText(Html.fromHtml(answerAll));
            holder.TvClassicAnalysis.setText(Html.fromHtml(analysisAll));

        }else{

            if (state==2 ||(PaperID==0&&ModelFrom==PaperDef.FROM_BASE_REVIEW_WRONG)||(PaperID==0&&ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG)) {
                holder.LayoutAnalysis.setVisibility(View.VISIBLE);
                String answerAll = "";
                String analysisAll = "";
                String stuAssessAll = "";
                for(int i =0;i<totalItemCount;i++){
                    answerAll = answerAll+"<br>"+(i+1)+"、"+answer[i]+"<br>";
                    if(analysis[i].equals("")){
                        analysis[i]="暂无解析";
                    }
                    analysisAll =analysisAll+"<br>"+(i+1)+"、"+analysis[i]+"<br>";
                    if(stuAssess[i].equals("")){
                        stuAssessAll = stuAssessAll+"<br>"+(i+1)+"、"+"未自评"+"<br>";
                    }else{
                        if(ModelFrom==PaperDef.FROM_GUESS_REVIEW) {
                            stuAssessAll = stuAssessAll + "<br>" + (i + 1) + "、" + stuAssess[i] + "分" + "<br>";
                        }else{
                            stuAssessAll = stuAssessAll + "<br>" + (i + 1) + "、" + stuAssess[i] + "<br>";
                        }
                    }

                }
                holder.TvAnswer.setText(Html.fromHtml(answerAll));

                double stuAllScore = 0.0;
                for(int i=0;i<totalItemCount;i++) {
                    if (!stuAssess[i].equals("")) {

                        if(!stuAssess[i].equals("错误")){
                            if(stuAssess[i].equals("正确")){
                                stuAllScore = stuAllScore+score/totalItemCount;
                            }else{
                                stuAllScore = stuAllScore+Double.valueOf(stuAssess[i]);
                            }
                        }

                    } else {
                        if (stuAnswer[i].equals(answer[i])) {
                            stuAllScore = stuAllScore+score/totalItemCount;
                        }
                    }
                }

                holder.TvScore.setText(String.valueOf(stuAllScore)+"分");

                holder.TvAnalysis.setText(Html.fromHtml(analysisAll));
                holder.TvStuAssess.setText(Html.fromHtml(stuAssessAll));

            }else{
                holder.LayoutAnalysis.setVisibility(View.GONE);
            }
            holder.LayoutClassicExample.setVisibility(View.GONE);
            holder.LayoutAnswerArea.setVisibility(View.VISIBLE);
        }

    }

    /*
    * 写入作答信息
    * */
    private void setStuAnswer(String strStuAnswer,int position){

        if(ModelFrom==PaperDef.FROM_BASE_REVIEW){
            InforBasicReview.getPaperContent().get(PaperID).getQueList().get(position).setStuAnswer(strStuAnswer);
            int totalItemCount = InforBasicReview.getPaperContent().get(PaperID).getTotalItemCount();
            String stuAnswerAll = "";
            String stuAssessAll = "";
            int totalItemCountTrue = 0;
            String thisStuAnswer = "";
            String thisAnswer = "";
            String thisStuAssess = "";
            int quesAnsweredItemCount = 0;
            for(int i=0;i<totalItemCount;i++){
                if(i==0){
                    stuAnswerAll = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                }else{
                    stuAnswerAll = stuAnswerAll+"#$*#"+InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = stuAssessAll+"#$*#"+InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                }
                thisStuAnswer = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                thisAnswer = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getAnswer();
                thisStuAssess = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                if(!thisStuAssess.equals("")) {
                    if (thisStuAssess.equals("正确") || thisStuAssess.equals("优秀")||thisStuAssess.equals("一般")) {
                        totalItemCountTrue++;
                    }
                }else {
                    if (thisStuAnswer.equals(thisAnswer)) {
                        totalItemCountTrue++;
                    }
                }

                if(!thisStuAnswer.equals("")||!thisStuAssess.equals("")){
                    quesAnsweredItemCount++;
                }

            }

            InforBasicReview.getPaperContent().get(PaperID).setStuAnswerNewAll(stuAnswerAll);
            InforBasicReview.getPaperContent().get(PaperID).setStuAssessNewAll(stuAssessAll);
            InforBasicReview.getPaperContent().get(PaperID).setCorrectRate(Control.getCorrectRate(Float.valueOf(totalItemCountTrue),Float.valueOf(totalItemCount)));
            InforBasicReview.getPaperContent().get(PaperID).setAnsweredItemCount(quesAnsweredItemCount);

        }else if(ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW){

            InforDifficultReview.getQueList().get(position).setStuAnswer(strStuAnswer);
            int totalItemCount = InforDifficultReview.getTotalItemCount();
            String stuAnswerAll = "";
            String stuAssessAll = "";
            int totalItemCountTrue = 0;
            String thisStuAnswer = "";
            String thisAnswer = "";
            String thisStuAssess = "";
            int quesAnsweredItemCount = 0;
            for(int i=0;i<totalItemCount;i++){
                if(i==0){
                    stuAnswerAll = InforDifficultReview.getQueList().get(i).getStuAnswer();
                    stuAssessAll = InforDifficultReview.getQueList().get(i).getStuAssess();
                }else{
                    stuAnswerAll = stuAnswerAll+"#$*#"+InforDifficultReview.getQueList().get(i).getStuAnswer();
                    stuAssessAll = stuAssessAll+"#$*#"+InforDifficultReview.getQueList().get(i).getStuAssess();
                }
                thisStuAnswer = InforDifficultReview.getQueList().get(i).getStuAnswer();
                thisAnswer = InforDifficultReview.getQueList().get(i).getAnswer();
                thisStuAssess = InforDifficultReview.getQueList().get(i).getStuAssess();
                if(!thisStuAssess.equals("")) {
                    if (thisStuAssess.equals("正确") || thisStuAssess.equals("优秀")||thisStuAssess.equals("一般")) {
                        totalItemCountTrue++;
                    }
                }else {
                    if (thisStuAnswer.equals(thisAnswer)) {
                        totalItemCountTrue++;
                    }
                }

                if(!thisStuAnswer.equals("")||!thisStuAssess.equals("")){
                    quesAnsweredItemCount++;
                }

            }

            InforDifficultReview.setStuAnswerNewAll(stuAnswerAll);
            InforDifficultReview.setStuAssessNewAll(stuAssessAll);
            InforDifficultReview.setCorrectRate(Control.getCorrectRate(Float.valueOf(totalItemCountTrue),Float.valueOf(totalItemCount)));
            InforDifficultReview.setAnsweredItemCount(quesAnsweredItemCount);

        }else if(ModelFrom==PaperDef.FROM_GUESS_REVIEW){
            InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(position).setStuAnswer(strStuAnswer);
            int totalItemCount = InforGuessTesting.getPaperContent().get(PaperID).getTotalItemCount();
            String stuAnswerAll = "";
            String stuAssessAll = "";
            int totalItemCountTrue = 0;
            String thisStuAnswer = "";
            String thisAnswer = "";
            String thisStuAssess = "";
            int quesAnsweredItemCount = 0;
            double thisScore = 0.0;
            for(int i=0;i<totalItemCount;i++){
                if(i==0){
                    stuAnswerAll = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                }else{
                    stuAnswerAll = stuAnswerAll+"#$*#"+InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = stuAssessAll+"#$*#"+InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                }
                thisStuAnswer = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                thisAnswer = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getAnswer();
                thisStuAssess = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();

                if(!thisStuAssess.equals("")){
                    thisScore = thisScore+Double.valueOf(thisStuAssess);
                }else{
                    if(thisAnswer.equals(thisStuAnswer)){
                        thisScore = thisScore+score/totalItemCount;
                    }
                }

                if(!thisStuAnswer.equals("")||!thisStuAssess.equals("")){
                    quesAnsweredItemCount++;
                }

            }

            InforGuessTesting.getPaperContent().get(PaperID).setStuAnswerNewAll(stuAnswerAll);
            InforGuessTesting.getPaperContent().get(PaperID).setStuAssessNewAll(stuAssessAll);
            InforGuessTesting.getPaperContent().get(PaperID).setCorrectRate(Control.getCorrectRate(Float.valueOf(String.valueOf(thisScore)), (float) score));
            InforGuessTesting.getPaperContent().get(PaperID).setAnsweredItemCount(quesAnsweredItemCount);
        }else if(ModelFrom== PaperDef.FROM_BASE_REVIEW_WRONG||ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG){
            InforWrongQues.get(PaperID).getQueList().get(position).setStuAnswer(strStuAnswer);
            int totalItemCount = InforWrongQues.get(PaperID).getTotalItemCount();
            String stuAnswerAll = "";
            String stuAssessAll = "";
            int totalItemCountTrue = 0;
            String thisStuAnswer = "";
            String thisAnswer = "";
            String thisStuAssess = "";
            int quesAnsweredItemCount = 0;
            for(int i=0;i<totalItemCount;i++){
                if(i==0){
                    stuAnswerAll = InforWrongQues.get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = InforWrongQues.get(PaperID).getQueList().get(i).getStuAssess();
                }else{
                    stuAnswerAll = stuAnswerAll+"#$*#"+InforWrongQues.get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = stuAssessAll+"#$*#"+InforWrongQues.get(PaperID).getQueList().get(i).getStuAssess();
                }
                thisStuAnswer = InforWrongQues.get(PaperID).getQueList().get(i).getStuAnswer();
                thisAnswer = InforWrongQues.get(PaperID).getQueList().get(i).getAnswer();
                thisStuAssess = InforWrongQues.get(PaperID).getQueList().get(i).getStuAssess();
                if(!thisStuAssess.equals("")) {
                    if (thisStuAssess.equals("正确") || thisStuAssess.equals("优秀")||thisStuAssess.equals("一般")) {
                        totalItemCountTrue++;
                    }
                }else {
                    if (thisStuAnswer.equals(thisAnswer)) {
                        totalItemCountTrue++;
                    }
                }

                if(!thisStuAnswer.equals("")||!thisStuAssess.equals("")){
                    quesAnsweredItemCount++;
                }

            }

            InforWrongQues.get(PaperID).setStuAnswerNewAll(stuAnswerAll);
            InforWrongQues.get(PaperID).setStuAssessNewAll(stuAssessAll);
            InforWrongQues.get(PaperID).setCorrectRate(Control.getCorrectRate(Float.valueOf(totalItemCountTrue),Float.valueOf(totalItemCount)));
            InforWrongQues.get(PaperID).setAnsweredItemCount(quesAnsweredItemCount);
        }
    }

    /**************************************************************************************************/
    /**************************************************************************************************/

    private class clickListener implements View.OnClickListener {
        public void onClick(View v) {
            if (holder.LayoutClassic.getVisibility() == GONE) {
                animationIvOpen();
                holder.LayoutClassic.setVisibility(View.VISIBLE);
            } else {
                animationIvClose();
                holder.LayoutClassic.setVisibility(View.GONE);
            }
        }
    }

    private void animationIvOpen() {
        RotateAnimation animation = new RotateAnimation(0, 180,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                0.5f);
        animation.setFillAfter(true);
        animation.setDuration(100);
        holder.IvClassic.startAnimation(animation);
    }

    private void animationIvClose() {
        RotateAnimation animation = new RotateAnimation(180, 0,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                0.5f);
        animation.setFillAfter(true);
        animation.setDuration(100);
        holder.IvClassic.startAnimation(animation);
    }
    /*********************************************************************************************************/
    /*********************************************************************************************************/

}